<template>
    <div>
        <span>{{codeValue}}</span>
    </div>
</template>
<script>
import { Toast } from "mint-ui";
export default {
    data() {
        return {
            validCode: true,
            codeValue: "获取验证码",
        };
    },
    props:['phone','phoneArea'],
    methods: {
        //获取验证码
        getCodeChild() {
            var that = this;
            var checkEmail = /^\w+@[a-z0-9]+\.[a-z]+$/i; //邮箱校验
            if(that.phone == ''){
                Toast({ message: "邮箱号不能为空！" });
                return false;
            }
            if(!checkEmail.test(that.phone)){
                Toast({ message: "请输入正确的邮箱格式！" });
                return false;
            } 
            var params = {
                mailbox:that.phone,
                type:'1'
            }    
            if (that.validCode == true) {
                that.getCode(params) 
                that.validCode = false;
                var newNum = 60;
                var timer = setInterval(function() {
                    newNum--;
                    //console.log(newNum);
                    that.codeValue = newNum;
                    // 调用code
                    if (newNum <= 0) {
                        clearInterval(timer);
                        that.codeValue = "获取验证码";
                        that.validCode = true;
                    }
                }, 1000);
            }
        },
        //获取验证码
        getCode(params){
            this.$axios.get(this.address.sendCode,{
                params:params
            }).then(res => {
                console.log(res.data)
                if(res.data.code == 200){
                        Toast({ message: "发送成功！" });
                    }else{
                        Toast({ message: "发送失败！" });
                    }
            })
        }

    }
};
</script>
<style lang="less" scoped>

</style>
